package acm.test;

import java.util.Scanner;
public class Main8 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] l=new int[n];
        int[] w=new int[n];
        int[] c=new int[n];
        for(int i=0;i<n;i++)
        {
            l[i]=scanner.nextInt();
            w[i]=scanner.nextInt();
            c[i]=scanner.nextInt();
        }
        int res=0;
        for(int i=0;i<n-1;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(c[i]!=c[j] && ((l[i]> l[j] && w[i]<w[j]) || (l[i]<l[j] && w[i]>w[j]))){
                    res++;
                    res%=(1e9+7);
                }
            }
        }
        System.out.println(res%(1e9+7));
    }
}

